//
//  GCMCBLRRequst.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/10/11.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMCBLRRequst.h"
#import "GCMChaobiaoModel.h"

@implementation GCMCBLRRequst



+ (NSURLSessionDataTask *)postCBLRDataWithId:(NSString *)areaId Success:(void (^) (id obj , NSError *))success{
    
    NSMutableDictionary *parameters= [[NSMutableDictionary alloc]init];
    
    parameters[@"ids"] = areaId;
//    NSLog(@"+nihao +1+  %@",parameters);
    return [[CZHAppNetAPIClient sharedClient] POST:CHAOBIAOSY_URL parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
//        NSLog(@"+nihao +1+  %@",dict);
        NSMutableArray *reciveListArray = [[NSMutableArray alloc]init];
        reciveListArray = [dict objectForKey:@"data"];
        if (success) {
            success(reciveListArray,nil);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}

+ (NSURLSessionDataTask *)postCBLRDataWithaId:(NSString *)areaId WithbId:(NSString *)buildId Withtdate:(NSString *)date Withbiao:(NSString *)biao Withvalid:(NSString *)valid Withpage:(NSString *)page Success:(void (^) (id obj , NSError *))success{
    NSMutableDictionary *parameter= [[NSMutableDictionary alloc]init];
    parameter[@"a_id"] = areaId;
    parameter[@"b_id"] = buildId;
    parameter[@"t_date"] = date;
    parameter[@"t_biao"] = biao;
    parameter[@"t_valid"] = valid;
    parameter[@"page"] = page;
    NSLog(@"+nihao +1+  %@",parameter);
    return [[CZHAppNetAPIClient sharedClient] POST:CHAOBIAOXQ_URL parameters:parameter success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
     NSLog(@"%@",dict);
        NSMutableArray *ReciveListArray = [[NSMutableArray alloc]init];
        NSMutableArray *reciveListArray = [[NSMutableArray alloc]init];
        if ([[dict objectForKey:@"data"] isKindOfClass:[NSArray class]]) {
        
            reciveListArray = [dict objectForKey:@"data"];
        
        for (NSDictionary *dict1 in reciveListArray) {
            NSMutableDictionary *dict2 = [NSMutableDictionary dictionaryWithDictionary:[CZHChangeNullString getValueFromDictionary:dict1]];
            GCMChaobiaoModel *cbModel = [[GCMChaobiaoModel alloc]init];;
//            NSLog(@"%@",cbModel);
            cbModel.room = [dict2 valueForKey:@"room"];
            cbModel.yzmc = [dict2 valueForKey:@"yzmc"];
            cbModel.money = [dict2 valueForKey:@"money"];
            cbModel.idd = [dict2 valueForKey:@"id"];
            cbModel.dj = [dict2 valueForKey:@"dj"];
            cbModel.syds = [dict2 valueForKey:@"syds"];
            cbModel.valid = [dict2 valueForKey:@"valid"];
            NSArray * arrar1 = [[dict2 valueForKey:@"byds"] componentsSeparatedByString:@"."];
            if (arrar1.count == 2) {
            NSRange range2 =  NSMakeRange(0, 1);
            NSString * subStr3 = [arrar1[1] substringWithRange:range2];
            NSString * iii = [NSString stringWithFormat:@"%@.%@",arrar1[0],subStr3];
            cbModel.byds = iii;
            }else{
            cbModel.byds = [dict2 valueForKey:@"byds"];
            }
            cbModel.a_id = [dict2 valueForKey:@"a_id"];
            cbModel.biao = [dict2 valueForKey:@"biao"];
            cbModel.item = [dict2 valueForKey:@"item"];
            cbModel.isSave = @"0";
            [ReciveListArray addObject:cbModel];
//              NSLog(@"---%@",dict2);
        }
        }
        if (success) {
            success(ReciveListArray,nil);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}
+ (NSURLSessionDataTask *)postCBXIUGAIWithData:(NSDictionary *)data Success:(void (^) (id obj , NSError *))success{
    
    return [[CZHAppNetAPIClient sharedClient] POST:CHAOBIAOXIUGAI_URL parameters:data success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
//        NSLog(@"++2+  %@",responseObject);
        if (success) {
            success(dict,nil);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}
+ (NSURLSessionDataTask *)postCBLRDataWithData:(NSDictionary *)data Success:(void (^) (id obj , NSError *))success{
    
    return [[CZHAppNetAPIClient sharedClient] POST:CHAOBIAOSUB_URL parameters:data success:^(NSURLSessionDataTask *task, id responseObject) {

        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
        if (success) {
            success(dict,nil);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        //NSLog(@"++2+  %@",error);
        if (success) {
            success(nil, error);
        }
    }];
    
}
+ (NSString *)stringWithJsonDictionary:(NSDictionary *)jsonDict
{
    if (jsonDict==nil || jsonDict.count==0) {
        return nil;
    }
    
    NSData *data = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:nil];
    
    @try {
        NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        return string;
    }
    @catch (NSException *exception) {
        
    }
    @finally {
        
    }
}

@end
